#include "game.h"
#include <string>
using namespace std;

Game::Game()
{
    world = Map(50,50);
    //set up heroes, villains, etc.
    monstlib[0].setAll("Dark Wizard"); //add attributes later
    //do same for all monsters in game

    herolib[0].setAll("Main Guy"); //add attributes later
    herolib[1].setAll("Arinoa"); //add attributes later
    //do same for all monsters in game

}

Game::~Game() {}

void Game::start()
{
    //run intro event
    intro();
    buildLocations();
    Map* tmp = &world;
    heroes.setMap(tmp);
    heroes.setLocation(2,0);

    //etc.

    while(!(heroes.isDefeated()))
    {
        heroes.idle();
    }

    cout << "---GAME OVER---\n\n\n";
    return;
}

void Game::intro()
{
    char choice = 't';
    string nm;
    cout << "Welcome to the game!\n";
    while (choice != 'Y' && choice != 'y')
    {
        cout << "Give me a hero's name, then press ENTER: ";
        cin >> nm;
        herolib[0].setName(nm);
        cout << "You typed in " << nm << "\nAre you satisfied with this choice? (Y = yes, N = no)\n:";
        cin >> choice;
    }
    heroes.addMember(herolib[0]);

    Monster darkwizard;
    darkwizard.setAll("Dark Wizard", 100, 100, 30, 30, 5, 40, 40, 80, 80, 1000, 300);
    Party firstenemy;
    firstenemy.addMember(darkwizard);
    system("CLS");
    cout << "You awake in a dark forest.\nYou don't remember your name, or where you came from.\n\n";
    system("PAUSE");
    system("CLS");
    cout << "You see dark ruins to the east.\n You begin walking towards them...\n\n";
    system("PAUSE");
    system("CLS");
    cout << "Suddenly, you hear shouting behind you.\n  A girl is running towards you in the distance.\n\n";
    cout << "But before you can react, a black-cloaked figure emerges from the darkness!\n";
    cout << "You quickly grab a stick to defend yourself!\n";
    system("PAUSE");
    system("CLS");
    heroes.attackParty(firstenemy);
    system("CLS");
    cout << "The strain of battle causes you to faint...\n\n";
    system("PAUSE");
    cout << "You awake in a strange building...\n\n";
    system("PAUSE");
    system("CLS");
    heroes.rest();
}

void Game::buildLocations() //this is going to be HUGE
{
    /*Town mytown = Town("Steubenville",20,20);
    NPC mike = NPC("Michael Roberts");
    mytown.addNPC(mike);
    world.Insert(mytown);*/
    string msg;
    Town *house1 = new Town("House of Kom-Kat.\n A lone Kom-Kat sits in a wooden chair.\n",0,0);
    NPC kom1 = NPC("Kom-Kat.\n 'Howdy!  This is the demo version of the game!'\n");
    house1->SetNPC(kom1);
    world.Insert(house1);

    Town *space = new Town("Ordinary Spot.\nWest: House\nEast:Mayor's House\nSouthish:Blacksmith\n",1,0);
    world.Insert(space);

    Town *mayohouse = new Town("Mayor's House.\n The mayor sits on a chair, examining a chart.\n",2,0);
    NPC mayor = NPC("Mayor of Terelliet.\n 'You are finally awake!\nMy daughter rescued you from those ruins, you ought to be more careful!\nWhat's your name?  You don't remember?\nWell, my daughter is in town doing errands,\nshe might be able to explain things better.'\n");
    mayohouse->SetNPC(mayor);
    world.Insert(mayohouse);

    Town *space2 = new Town("Ordinary Spot.\nEast:Inn\nWest:Mayor's House\nSouthish: Terelliet Academy, General Store\nThere is a dog here.\n",3,0);
    NPC dog = NPC("Dog.\n'Woof!  Woof!'\n");
    space2->SetNPC(dog);
    world.Insert(space2);

    Town *inn = new Town("Inn.\nA white-bearded man sits behind a counter, looking glum.\n",4,0);
    NPC wbman = NPC("Johnathan Baker.\n'My inn used to be prized and famous.\nBut since people found out you can REST anywhere where there aren't monsters,\nno one wants to sleep here anymore!\nI'm broke!'\n");
    inn->SetNPC(wbman);
    world.Insert(inn);

    Town *na = new Town("NA", 5, 0);
    world.Insert(na);

    Town *space3 = new Town("Ordinary Spot.\nSouth:Blacksmith\nNorth:House\nWestish:Mayor's House, Terelliet Academy\nThere is a dog here.\n",0,1);
    space3->SetNPC(dog);
    world.Insert(space3);

    Town *space4 = new Town("Ordinary Spot.\nNorthish: House and Mayor's House\nSouthish:Blacksmith and Terelliet Academy\nA man with an umbrella sits in the grass.\nThe sky is sunny and cloudless.\n",1,1);
    NPC umbrella_man = NPC("Renaldo.\n'I am quite certain that it is going to rain!\nSee those dark clouds to the south?\nYou'd better get indoors!'\n");
    space4->SetNPC(umbrella_man);
    world.Insert(space4);

    Town *space5 = new Town("Ordinary Spot.\nNorth:Mayor's House\nSouth:Terelliet Academy\nWestish:House,Blacksmith\nEastish:Inn,General Store\n", 2,1);
    world.Insert(space5);

    Town *space6 = new Town("Extraordinary Spot.\nNorthish:Mayor's House,Inn\nSouthish:Terelliet Academy,General Store\nThis spot is extraordinary!\n", 3,1);
    NPC ghost = NPC("Ghost.\n'How did you find me???\nI wasn't even in the location description!'\n");
    space6->SetNPC(ghost);
    world.Insert(space6);

    Town *space7 = new Town("Ordinary Spot.\nNorth:Inn\nSouth:General Store\nWestish:Mayor's House,Telleriet Academy.\nThere is a Talking Map here.\n",4,1);
    NPC talkingmap = NPC("Talking Map.\n'Hallo!\n- - - - - -\nH   M   I -\n        x -\nB   A   G -\n          -\nH       H -\n- -   - - -\n\nx- you are here\tH- House\nM-Mayor's House\tI-Inn\nB-Blacksmith\tA-Academy\nG- General Store'\n");
    space7->SetNPC(talkingmap);
    world.Insert(space7);

    Town *space8 = new Town("NA",5,1);
    world.Insert(space8);

    Town *blacksmith = new Town("Blacksmith.\nA chubby, tall man strikes a sword on an anvil.\n", 0,2);
    NPC bsmith = NPC("Bill Knife.\n'I'm pretty good aim, hitting this sword, ain't I?\nOUCH! Dang blast it!\nYou made me pound my finger!'\n");
    blacksmith->SetNPC(bsmith);
    world.Insert(blacksmith);

    Town *space9 = new Town("Ordinary Spot.\nWest:Blacksmith\nEast:Terelliet Academy\nNorthish:House,Mayor's House\nSouthish:House\nLost yet?  There is a Talking Map just south of the Inn.\n", 1,2);
    world.Insert(space9);

    Town *academy = new Town("Terelliet Academy.\nA wise mage holding a really big stick looks at you.\n", 2,2);
    NPC mage = NPC("Wikel Eggknight.\n'Remember, you can't run away from a battle!\nBe sure to REST often!'\n");
    academy->SetNPC(mage);
    world.Insert(academy);

    Town *spaceten = new Town("Ordinary Spot.\nWest:Terelliet Academy\nEast:General Store\nSouthish: House\nNorthish:Inn,Mayor's House\nThere is a dog here.\n",3,2);
    NPC dog2 = NPC("Woofward.\n'I say, good chap, do you have the time?'\n");
    spaceten->SetNPC(dog2);
    world.Insert(spaceten);

    Town *genstore = new Town("General Store.\nA colonel stands at attention near the back of the room.\n", 4,2);
    NPC colonel = NPC("Colonel Munther, sir!\nYou don't have an army, sir!\nWe only sell generals here, sir!\n");
    genstore->SetNPC(colonel);
    world.Insert(genstore);

    Town *na3 = new Town("NA", 5,2);
    world.Insert(na3);

    Town *shadow = new Town("Shadowy Spot.\nNorth:Blacksmith\nSouth:House\nEastish:Terelliet Academy\n", 0,3);
    world.Insert(shadow);

    Town *shadow2 = new Town("Shadowy Spot.\nNorthish:Blacksmith,Terelliet Academy\nSouthish:House\n", 1,3);
    world.Insert(shadow2);

    Town *shadow3 = new Town("Shadowy Spot.\nNorth:Terelliet Academy\nWestish:Blacksmith,House\nTo the far south, there is a gate.", 2,3);
    world.Insert(shadow3);

    Town *shadow4 = new Town("Shadowy Spot.\nWestish:Terelliet Academy\nEastish:General Store,House\n", 3,3);
    world.Insert(shadow4);

    Town *shadow5 = new Town("Shadowy Spot.\nNorth:General Store\nSouth:House\n", 4,3);
    world.Insert(shadow5);

    Town *na4 = new Town("NA",5,3);
    world.Insert(na4);

    Town *house2 = new Town("House of Raga.\nA young mage is practicing here.\n", 0,4);
    NPC raga = NPC("Raga!\n'Ooooh... I'm so jealous of that Arinoa!\nWhy can't I be the top Academy student?  Hmmph!\nI'll show her!'\n");
    house2->SetNPC(raga);
    world.Insert(house2);

    Town *shadow6 = new Town("Stormy, Shadowy Spot.\nWest:House\nEastish:Gate\nThere is a wall to the south.\nDark storm clouds billow above you.\n",1,4);
    world.Insert(shadow6);

    Town *shadow7 = new Town("Stormy, Shadowy Spot.\nSouth:Gate\nDark storm clouds billow above you.\n",2,4);
    world.Insert(shadow7);

    Town *shadow8 = new Town("Stormy, Shadowy Spot.\nWestish:Gate\nEast:House\nThere is a wall to the south.\nDark storm clouds billow above you.\n",3,4);
    world.Insert(shadow8);

    AddTown *house3 = new AddTown("House of Wind.\n",4,4);
    world.Insert(house3);

    Town *na5 = new Town("NA",5,4);
    world.Insert(na5);

    Town *na6 = new Town("NA",0,5);
    world.Insert(na6);

    Town *na7 = new Town("NA",1,5);
    world.Insert(na7);

    Town *gate = new Town("Gate.\nThe gate is currently locked.\nOnly exit is NORTH.\n Here, a chilly rain falls.\n", 2,5);
    world.Insert(gate);

    Town *na8 = new Town("NA",3,5);
    world.Insert(na8);

    Town *na9 = new Town("NA",4,5);
    world.Insert(na9);

    Town *na10 = new Town("NA",5,5);
    world.Insert(na10);

    Town *endofdemo = new Town("End Of Demo.\nA sign reads: 'There's nothing more to see!\n  Quit the game and buy the full version today!'\n", 50, 50);
    world.Insert(endofdemo);

    Town *naa = new Town("NA", 49, 50);
    world.Insert(naa);

    Town *nab = new Town("NA", 51, 50);
    world.Insert(nab);

    Town *nac = new Town("NA", 50, 49);
    world.Insert(nac);

    Town *nad = new Town("NA", 50, 51);
    world.Insert(nad);
}

/*void Game::criticalEvent(int code) //in process... chris change
{
    switch (code)
    {
        case 1:*/

